/**
 * 
 */
package info.niwota.icoe;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.Window;
import android.view.WindowManager;

/**
 * @author qiangli
 *
 */
public class RestrictedActivity extends MainActivity {
	public static final String ACTION_POWERUP_QUIT = "info.niwota.intent.ACTION_POWERUP_QUIT";
	private static final String TAG = "RestrictedActivity";

	@Override
	public void onCreate(Bundle savedInstanceState) {
		setSecure();
		
		super.onCreate(savedInstanceState);
	}

	@Override
	protected boolean isGuarded() {
		return true;
	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (Debug.DEBUG) {
			Log.d(TAG, "onKeyDown " + isGuarded() + " key: " + keyCode);
		}
		if (keyCode == KeyEvent.KEYCODE_BACK) {
			quit();
			return true;
		}
		
		return true;
	}

	protected void quit() {
		finish();
		
		Intent i = new Intent(ACTION_POWERUP_QUIT);
		sendOrderedBroadcast(i, null);
	}
	
	private void setSecure() {
		final Window w = getWindow();
		//w.requestFeature(Window.FEATURE_NO_TITLE);
		w.clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
		//w.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
		w.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
	}
}
